package com.csdj.controller;

import com.csdj.pojo.TUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;

/**
 * Author : 今晚几点睡_Ada
 * Date: 2022/9/7
 * Time: 20:40
 * 注:
 */
@Api(tags = "路由 控制页面跳转")
@Controller
public class RouterController {


    @ApiOperation("跳转到login页面")
    @GetMapping("/toLogin")
    public String toLogin() {
        return "login";
    }
    @ApiOperation("跳转到Register")
    @GetMapping("/toRegister")
    public String toRegister() {
        return "register";
    }
    @ApiOperation("定制首页")
    @GetMapping("/")
    public String index(Model model) {
        model.addAttribute("isLogin",false);
        return "index";
    }
    @ApiOperation("登陆后跳转")
    @GetMapping("/toIndex")
    public String toIndex(Model model, HttpSession session) {
        TUser loginUser = (TUser) session.getAttribute("LoginUser");
        if (loginUser!=null){
            model.addAttribute("isLogin",true);
        }
        return "index";
    }
}
